package com.qk.management.controller;


import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result getActivityByType(@PathVariable String type) {
        List<Activity> activities = activityService.getActivityByType(type);
        return Result.success(activities);
    }

    @GetMapping
    public Result getActivities(ActivityDTO activityDTO) {
        PageResult<ActivityDTO> pageResult = activityService.getActivities(activityDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        activityService.deleteActivity(id);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody ActivityDTO activityDTO) {
        activityService.addActivity(activityDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id) {
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result updateActivity(@RequestBody ActivityDTO activityDTO) {
        activityService.updateActivity(activityDTO);
        return Result.success();
    }

}
